@echo off
chcp 65001 >nul
echo ========================================
echo   配置Windows防火墙
echo ========================================
echo.
echo 此脚本将配置Windows防火墙，允许外部访问系统
echo.

:: 检查管理员权限
net session >nul 2>&1
if %errorLevel% neq 0 (
    echo [错误] 请以管理员身份运行此脚本！
    pause
    exit /b 1
)

echo [1/2] 添加防火墙规则（端口8000 - 后端API）...
netsh advfirewall firewall delete rule name="南昌旅游系统-后端API" >nul 2>&1
netsh advfirewall firewall add rule name="南昌旅游系统-后端API" dir=in action=allow protocol=TCP localport=8000
if %errorLevel% equ 0 (
    echo ✓ 端口8000已开放
) else (
    echo ✗ 端口8000开放失败
)

echo.
echo [2/2] 添加防火墙规则（端口8080 - 前端）...
netsh advfirewall firewall delete rule name="南昌旅游系统-前端" >nul 2>&1
netsh advfirewall firewall add rule name="南昌旅游系统-前端" dir=in action=allow protocol=TCP localport=8080
if %errorLevel% equ 0 (
    echo ✓ 端口8080已开放
) else (
    echo ✗ 端口8080开放失败
)

echo.
echo ========================================
echo   ✅ 防火墙配置完成！
echo ========================================
echo.
echo 获取本机IP地址:
ipconfig | findstr /C:"IPv4" | findstr /V "127.0.0.1"
echo.
echo 其他人可以通过以下地址访问:
echo   前端: http://你的IP:8080
echo   API:  http://你的IP:8000/api/
echo.
pause

